<?php
class IndexController extends Zenddn_Controller_Action{
    
    
    public function init(){
        parent::init();
        parent::loadTemplate('magashop');
        $this->view->page = "home";
    }
    
    public function indexAction(){
        $request = $this->_request;
        
        $setting_model = new Default_Model_Setting();
        $setting = $setting_model->getSetting('general');
        
        $itemPerPage = 6;
        $outOfStockLevel = 3;
        
        if($setting){
            $setting = unserialize($setting);
            $itemPerPage = $setting['product_items_per_page'];
            $outOfStockLevel = $setting['out_of_stock_level'];
        }
        
        $currentPage = $request->getParam('page', 1);
        $pageRange = 5;
        
        $model = new Default_Model_Product();
        
        $brand_model = new Default_Model_Brand();
        $brands = $brand_model->getDatas();
        
        $adapter = new Zend_Paginator_Adapter_DbSelect($model->getQuery());
        $paginator = new Zend_Paginator($adapter);
        
        $paginator->setItemCountPerPage($itemPerPage);
        $paginator->setPageRange($pageRange);
        $paginator->setCurrentPageNumber($currentPage);
        
        $this->view->data = $paginator;
        $this->view->brands = $brands;
        $this->view->itemPerPage = $itemPerPage;
        $this->view->currentPage = $currentPage;
        $this->view->outOfStockLevel = $outOfStockLevel;
    }
}